/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;

/**
 *
 * @author 52461
 */
@ControllerBind(controllerKey = "/view/count")
public class CountCtrl extends Controller {

    public void index() {
        render("/view/count.jsp");
    }

    public void getDeviceList(){
        String sql=" select DISTINCT DEVICEID as name,count(DISTINCT UUID) as value "
                + "from lis_testresult  group by DEVICEID";
        renderJson(Db.use("mysql").find(sql));
    }
    public void getDeviceDate(){
        String sql="select DISTINCT DEVICEID as name,count(DISTINCT UUID) as value from "
                + "(select DEVICEID,UUID from lis_testresult where MEASURETIME BETWEEN '"+getPara("start")+"' AND '"+getPara("end")+"') a group by DEVICEID";
              List<Record> re= Db.use("mysql").find(sql);
              System.out.println(re+"----------+++++++++++++++++----------");
              if(re!=null){
                    renderJson(re);
              }else{
                  renderText("false");
              }
    }
    
    public void getDoctorList(){
        String sql="select DISTINCT CHECKOPERATOR as name,COUNT(CHECKOPERATOR) as value from "
                + "(select CHECKOPERATOR from lis_samplecollection where CHECKOPERATOR is not null AND CHECKTIME BETWEEN '2016-8-1' AND '2016-9-12') a GROUP BY CHECKOPERATOR ";
        renderJson(Db.use("mysql").find(sql));
    }
    public void getDoctorDate(){
        String sql="select DISTINCT CHECKOPERATOR as name,COUNT(CHECKOPERATOR) as value from "
                + "(select CHECKOPERATOR from lis_samplecollection where CHECKOPERATOR is not null AND CHECKTIME BETWEEN '"+getPara("start")+"' AND '"+getPara("end")+"') a GROUP BY CHECKOPERATOR ";
        List<Record> re= Db.use("mysql").find(sql);
              if(re!=null){
                    renderJson(re);
              }else{
                  renderText("false");
              }
    }
    public void getPatientToday(){
        String sql="select RECEIVETIME as time,COUNT(*) as value from (select * from lis_samplecollection where DATE_FORMAT(RECEIVETIME,'%Y-%m')=date_format(now(),'%Y-%m')  ORDER BY RECEIVETIME) a " 
                + " GROUP BY DATE_FORMAT(RECEIVETIME,'%Y-%m-%d')";
         renderJson(Db.use("mysql").find(sql));
    }
    public void getPatientMoth(){
        String sql="select RECEIVETIME as time,COUNT(*) as value from (select * from lis_samplecollection where DATE_FORMAT(RECEIVETIME,'%Y-%m')='"+getPara("date")+"'  ORDER BY RECEIVETIME) a " 
                + " GROUP BY DATE_FORMAT(RECEIVETIME,'%Y-%m-%d')";
         renderJson(Db.use("mysql").find(sql));
    }
    public void getPatientSex(){
        String sql="select RECEIVETIME as time,COUNT(SEX) as value  " +
            "from (select RECEIVETIME,SEX from lis_samplecollection b LEFT JOIN  " +
            "lis_patient c on b.INFOPK=c.PK where DATE_FORMAT(RECEIVETIME,'%Y-%m')=date_format(now(),'%Y-%m') AND SEX='男' ORDER BY RECEIVETIME) a " +
            "GROUP BY DATE_FORMAT(RECEIVETIME,'%Y-%m-%d')";
        renderJson(Db.use("mysql").find(sql));
    }
    public void getPatientSexDay(){
        String sql="select RECEIVETIME as time,COUNT(SEX) as value  " +
            "from (select RECEIVETIME,SEX from lis_samplecollection b LEFT JOIN  " +
            "lis_patient c on b.INFOPK=c.PK where DATE_FORMAT(RECEIVETIME,'%Y-%m')='"+getPara("date")+"' AND SEX='男' ORDER BY RECEIVETIME) a " +
            "GROUP BY DATE_FORMAT(RECEIVETIME,'%Y-%m-%d')";
        renderJson(Db.use("mysql").find(sql));
    }
 
}
